﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
using DAL;
using BLL;

public partial class Plublic_TermCurrentAccount : System.Web.UI.Page
{
    String StrConn = WebConfigurationManager.ConnectionStrings["conn"].ConnectionString.ToString();
    TermCurrentHandler objTermCurrentHandler = new TermCurrentHandler();
    TransactionHandler objTransactionHandler = new TransactionHandler();
    int indexReLoad;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            Response.Redirect("Default.aspx");
        }
        if (!IsPostBack)
        {
            DataBindGridView();
        }
    }

    protected void DataBindGridView()
    {
        int UserId = Convert.ToInt32(Session["UserId"]);

        DataTable dt = objTermCurrentHandler.GetTermCurrentTable(UserId, StrConn);

        GridView1.DataSource = dt;
        GridView1.DataBind();

    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName != String.Empty)
        {
            int index = Convert.ToInt32(e.CommandArgument);
            indexReLoad = index;
            switch (e.CommandName.ToString())
            {
                case "View":
                    this.loadGridViewDetails(index);
                    this.loadAallTranSacTion(index);
                    break;

            }
        }
    }

    protected void loadGridViewDetails(int key)
    {

        string AccNumber = GridView1.DataKeys[key].Value.ToString();

        DataTable dt = objTransactionHandler.GetTransactionTable(AccNumber, StrConn);
        GridViewDetails.DataSource = dt;
        GridViewDetails.DataBind();
    }

    protected void loadAallTranSacTion(int key)
    {
        string AccNumber = GridView1.DataKeys[key].Value.ToString();
        DataTable dt = objTransactionHandler.GetAllTransactionTable(AccNumber, StrConn);
        GridViewAll.DataSource = dt;
        GridViewAll.DataBind();

    }

    protected void GridViewDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName != String.Empty)
        {
            int index = Convert.ToInt32(e.CommandArgument);

            switch (e.CommandName.ToString())
            {
                case "Confirm":
                    UpdateStatus(index);
                    this.loadGridViewDetails(indexReLoad);

                    break;

            }
        }
    }

    protected void UpdateStatus(int key)
    {
        string tranID = GridViewDetails.DataKeys[key].Value.ToString();

        objTransactionHandler.UpdateStatusTransaction(tranID, StrConn);
    }

}